package com.or.common.compose;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.or.common.R;

public class CMTitleBar extends RelativeLayout {

    ImageView ivBack;
    TextView tvCenterTitle;
    TextView tvRightTitle;

    public CMTitleBar(Context context) {
        super(context);
        this.intView(context);
    }

    public CMTitleBar(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.intView(context);
    }

    public CMTitleBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.intView(context);
    }

    void intView(Context context) {
        LayoutInflater.from(context).inflate(R.layout.cm_layout_title_bar, this, true);
        ivBack = findViewById(R.id.iv_back);
        tvCenterTitle = findViewById(R.id.tv_center_title);
        tvRightTitle = findViewById(R.id.tv_right_title);
        ivBack.setOnClickListener(view -> ((Activity) context).finish());
    }

    public CMTitleBar setBackGone() {
        ivBack.setVisibility(GONE);
        return this;
    }

    public CMTitleBar setCenterTitle(String title) {
        tvCenterTitle.setText(title);
        return this;
    }

    public CMTitleBar setRightTitle(String title) {
        tvRightTitle.setText(title);
        tvRightTitle.setVisibility(VISIBLE);
        return this;
    }

    public TextView getRightTitle() {
        return tvRightTitle;
    }


}
